package cn.itsource.hbc.org.controller;


import cn.itsource.hbc.org.domain.Shop;
import cn.itsource.hbc.org.domain.Systemdictionarytype;
import cn.itsource.hbc.org.query.ShopQuery;
import cn.itsource.hbc.org.query.SystemdictionarytypeQuery;
import cn.itsource.hbc.org.service.IShopService;
import cn.itsource.hbc.org.service.ISystemdictionarytypeService;
import cn.itsource.utils.AjaxResult;
import cn.itsource.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    @PutMapping
    public AjaxResult saveOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){

        try {
            if(systemdictionarytype.getId()!=null){
                systemdictionarytypeService.update(systemdictionarytype);
            }else {
                systemdictionarytypeService.save(systemdictionarytype);

            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("操作失败"+e.getMessage());
        }

    }



    @GetMapping
    public List<Systemdictionarytype> loadAll(){

        return systemdictionarytypeService.loadAll();
    }


    @GetMapping("/{id}")
    public Systemdictionarytype loadById(@PathVariable("id") Long id){

        return systemdictionarytypeService.loadById(id);

    }



    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("删除失败"+e.getMessage());
        }

    }

    @PostMapping
    public PageResult<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery query){

        return  systemdictionarytypeService.queryPage(query);
    }

    @PatchMapping
    public AjaxResult allDelete(@RequestBody Long[]ids){
        try {
            systemdictionarytypeService.allDelete(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("批量删除失败"+e.getMessage());
        }


    }

}
